<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="org.factory.*,org.vo.*"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>check</title>
</head>
<%
	request.setCharacterEncoding("GBK");
%>
<body>
	<%
		boolean flag = false;
		String keyWord = request.getParameter("id");
		if (keyWord == null) {
			keyWord = "";
		}
		int id = 0;
		try {
			id = Integer.parseInt(keyWord);
		} catch (Exception e) {
	%>
	<script type="text/javascript">
		alert("id应为数字!");
	</script>
	<%
		}
		User user=null;
		try{
		   user = DAOFactory.getUserDAOInstance().findById(id);
		}catch(Exception e){
			session.setAttribute("error", "账号不存在");              //id不存在
			response.setHeader("Refresh", "0;URL=error.jsp");
		}
		if (user != null) {
			String passwd = user.getPasswd();
			if (passwd != null
					&& passwd.equals(request.getParameter("passwd")))
				flag = true;
			else{
				session.setAttribute("error", "密码错误");             //id存在，但密码不匹配
				response.setHeader("Refresh", "0;URL=error.jsp");
				}
		}
		
		if (flag) {                                          //查询成功，跳转到主页面
			session.setAttribute("user", user);
			response.setHeader("Refresh", "0;URL=index.jsp");

		} 	
	%>  
</body>
</html>